package com.example.campuslink.commen.adpter

import android.annotation.SuppressLint
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.core.CoreAdapter
import com.example.campuslink.commen.core.CoreViewHolder
import com.example.campuslink.databinding.AdapterAiHistoryBinding
import com.example.campuslink.model.DeepSeekTalkData
import com.example.campuslink.viewModel.ai.InquiriesViewModel

class AiHistoryAdapter(vm: InquiriesViewModel) :
    CoreAdapter<AdapterAiHistoryBinding, InquiriesViewModel, DeepSeekTalkData>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_ai_history
    }

    override fun onBindViewHolder(holder: CoreViewHolder, @SuppressLint("RecyclerView") position: Int) {
        super.onBindViewHolder(holder, position)
        holder.binding.root.findViewById<TextView>(R.id.tv_title).text =
            mListData[position].problem
        holder.binding.root.setOnClickListener({
            mViewModel?.jumpToDetail(mListData[position])
        })
        holder.binding.root.setOnLongClickListener(object : View.OnLongClickListener {
            override fun onLongClick(p0: View?): Boolean {
                AlertDialog.Builder(holder.itemView.context)
                    .setTitle("删除该条历史")
                    .setMessage("是否要删除该条历史？")
                    .setPositiveButton("确认") { dialog, _ ->
                        // 确认按钮点击逻辑
                        mViewModel?.deleteHistoryList(mListData[position])
                        dialog.dismiss()
                    }
                    .setNegativeButton("取消") { dialog, _ ->
                        dialog.dismiss()
                    }
                    .create()
                    .show()

                return true
            }
        })
    }
}